package com.baicaoyuan.web.repository;


import com.baicaoyuan.web.model.JzzBusinessDO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 功能描述：
 *
 * @author 罗富祥
 * 创建时间： 2018/1/4
 * 版权：
 */
@Repository
public interface JzzBusinessRepository extends JpaRepository<JzzBusinessDO, Long> {

    @Query(value = "SELECT * from t_jzz_business where `status` = ?1 and (source_user_id = ?2 or target_user_id = ?2) order by ?#{#pageable}",
            countQuery = "SELECT count(*) from t_jzz_business where `status` = ?1 and (source_user_id = ?2 or target_user_id = ?2)", nativeQuery = true)
    Page<JzzBusinessDO> queryMyDoneBusiness(String status, Long userId, Pageable pageable);

    Page<JzzBusinessDO> findAllByStatus(String status, Pageable pageable);

    Page<JzzBusinessDO> findAllByTypeAndStatusNotIn(String type, List<String> status, Pageable pageable);

    List<JzzBusinessDO> findBySourceUserIdAndStatusIn(Long sourceUserId, List<String> status);

    List<JzzBusinessDO> findBySourceUserId(Long sourceUserId);

    List<JzzBusinessDO> findByTargetUserId(Long targetUserId);

    List<JzzBusinessDO> findAllByTargetUserIdAndStatus(Long targetId, String status);
}
